package thread;

public class Demo18 {

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            //获取线程的引用
            Thread currentThread = Thread.currentThread();

            while (!currentThread.isInterrupted()) {
                System.out.println("hello,Thread");

                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });


        t.start();

        Thread.sleep(3000);
        //在主线程中，控制 t 线程终止，设置上述标志位
        t.interrupt();
    }

}
